<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="layout" content="portalForAppTemplate"/>
  <!--   <script src="http://res..qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="https://res..qq.com/open/js/jweixin-1.0.0.js"></script> -->
    <asset:javascript src="jquery-2.1.3.js"/>
    <asset:javascript src="jquery-1.12.3.min.js"/>
    <asset:stylesheet src="homer/vendor/sweetalert/lib/sweet-alert.css"/>
    <asset:javascript src="homer/vendor/sweetalert/lib/sweet-alert.min.js"/>
    <title>意见反馈</title>
    <style>
    .weui_media_title {
        font-size: 1.2rem !important;
    }

    .weui_media_box .weui_media_desc {
        -webkit-line-clamp: 4;
    }

    .field {
        width: 100%;
    }
    ::-webkit-input-placeholder {
        font-size: 1.2rem;
        color: #ccc;
        font-family: inherit !important;
    }

    ::-moz-placeholder {
        font-size: 1.2rem;
        color: #ccc;
        font-family: inherit  !important;
    }

    :-ms-input-placeholder {
        font-size: 1.2rem;
        color: #ccc;
        font-family: inherit  !important;
    }

    :-moz-placeholder {
        font-size: 1.2rem;
        color: #ccc;
        font-family: inherit;
    }
.weui_textarea,.weui_media_text input{
    font-size: 1.2rem;
     font-family: inherit;
}
.preview{
    width: 77px;
    height: 77px;
}
    /*图片上传*/
    .file-title {
        font-size: 1.2rem;
        height: 3.5rem;
        line-height: 3.5rem;
        background-color: #e1e1e1;
    }

    .file-title .status {
        color: #CD001A;
    }
    .title-desc {
        padding: 0 15px;
    }

    .preview {
        height: 77px;
        width: 77px;
    }

     .weui_uploader_input_wrp {
        margin-bottom: 0;
    }
    .weui_uploader_input_wrp:after, .weui_uploader_input_wrp:before {
        z-index: -1;
    }

    .file-input {
        position: relative;
        float: left;
    }
    .btn-file {
        width: 80%;
    }
    .krajee-default.file-preview-frame {
        padding: 0;
        margin: 0;
        border: none;
    }
    .kv-upload-progress .progress,
    .btn-file .glyphicon-folder-open,
    .file-thumbnail-footer {
        display: none;
    }
    .krajee-default.file-preview-frame .kv-file-content {
        width: auto;
        height: auto;
        max-width: 130px;
        max-height: 130px;
    }
    .hidden-xs {
        display: none !important;
    }
    .file-preview-image {
        max-width:80%;
        max-height:80%;
    }
        #kvFileinputModal{
            display: none;
        }


    .borrowerDiv2{
        margin-left: 100px;
    }
    .file-preview-image{
        width: 76px!important;
        height: 76px!important;
        max-width: 76px!important;
        max-height: 76px!important;
    }
    .file-error-message ul{
        display: none;
    }
    .file-error-message button{
        display: none;
    }
        /*模态框*/
        .message, .helpMsg {
            width: 320px;
            height: 190px;
            padding-top: 80px;
        }
    </style>
</head>

<body>
<nav class="nav">
    <a href="javascript:void(0);" onclick="javascript:window.history.back();"><</a>
    反馈建议
</nav>
<g:form action="suggestSave" name="suggestForm">
    <input type="hidden" value="${this.backUrl}" name="backUrl" id="backUrl"/>
    <input type="hidden" value="${this.house.id}" name="id" id="house"/>
    <input type="hidden" value="${this.timestamp}" name="timestamp" id="timestamp"/>
    <input type="hidden" value="${this.nonceStr}" name="nonceStr" id="nonceStr"/>
    <input type="hidden" value="${this.signature}" name="signature" id="signature"/>
    <input type="hidden" value="${this.accessToken}" name="accessToken" id="accessToken"/>
    <input type="hidden" id="evaluateFiles" name="evaluateFiles" value="">
    <input type="hidden" id="fileNames" name="fileNames" value="">

    	<g:if test="${!contactId }">
            <input type="hidden" name="x:contactId" id="contactId" value="${params.contactId}" />
        </g:if>
        <g:else>
	    <input type="hidden" name="x:contactId" id="contactId" value="${contactId}" />
        </g:else>

    <div class="weui_panel weui_panel_access">
        <div class="weui_panel_bd">
            <div class="weui_media_box weui_media_text">
                <h4 class="weui_media_title">请填写您的期望押品评估总价(<span class="colorRed">必填</span>)</h4>
                <g:field class="field" type="number" name="appliedTotalPrice" id="appliedTotalPrice" value="${this.house?.appliedTotalPrice}" placeholder="例如：400万"/>
            </div>
            <div class="weui_media_box weui_media_text">
                <h4 class="weui_media_title">请填写您的反馈原因(<span class="colorRed">必填</span>)</h4>
                <g:textArea class="weui_textarea field" type="text" id="reasonOfPriceAdjustment" name="reasonOfPriceAdjustment" rows="4"
                         placeholder="例如：房层带阁楼、附带车库（需提供产证）、是否为学区房、央产房、房改房、是否存在比其他评估机构低的情况等。"
                         value="${this.house?.reasonOfPriceAdjustment}" />
            </div>
        </div>
    </div>

    <div class="weui_cell">
        <div class="weui_cell_bd weui_cell_primary">
            <div class="weui_uploader">
                <div class="weui_uploader_bd">
                    <ul class="weui_uploader_files" id="fileList">
                    </ul>
                    <div class="weui_uploader_input_wrp">
                        <!-- <input type="button" id="pickSerialPic" class="weui_uploader_input" onclick="uploadPropertyImg()"> -->
			<input type="hidden" name="propertyType" value="${com.next.AttachmentType.findByName("估值附回材料")?.id}" id="propertyType">
                        <input type="file" name="file" id="propertyPicture" style="opacity: 0;height: 76px;width: 76px"  multiple>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bigBtn" style="margin-bottom: 20px">
        <input class="linkBtn weui_btn weui_btn_primary" value="提交" id="submitBtn" type="button" />
    </div>
</g:form>




%{--提示信息和验证--}%
<div class="message-box" style="top: 20%;">
    <div class="helpMsg hide"></div>
    <g:if test="${flash.message}">
        <div class="message" role="status">
            ${flash.message}
        </div>
    </g:if>
</div>

<asset:javascript src="homer/vendor/fileinput.js"></asset:javascript>
<asset:javascript src="homer/vendor/zh.js"></asset:javascript>
<asset:javascript src="homer/vendor/fileinput.css"></asset:javascript>
<script>

    $("#propertyPicture").click(function () {
      var borrowerType=$("#propertyType").val()
      //$(".borrower1").val("marialFile")
      uploadImg("propertyPicture",borrowerType);
      })

      function getUploadToken() {
        var token = ""
        $.ajax({
            type: "POST",
            url: "https://" + window.location.host + "/attachments/getUploadToken1",
            async:false,
            success: function (data) {
                if (data.status == "success") {
                    token = data.token;
                    console.log("getUploadToken1 success");
                }
            },
        });
        return token
    }

    function uploadImg(ownerType,type) {
        var opportunityId=$("#contactId").val()
        console.log("ownerType: "+ownerType)
        $("#"+ownerType).fileinput({
            language: 'zh', //设置语言
//            uploadUrl:"opporImg?opportunityId="+opportunityId+"&type="+type+"&ownerType="+ownerType, //上传的地址
//            uploadUrl:"https://upload-z1.qiniup.com?x:opportunityId="+opportunityId+"&x:type="+type+"&key="+key+"&x:description="+description+"&token="+token, //上传的地址
            uploadUrl:"https://upload-z1.qiniup.com", //上传的地址
//            uploadUrl:"test",
            allowedPreviewTypes : ['image'],
            allowedFileTypes: ['image'],
            allowedFileExtensions: ['jpg','jpeg', 'gif', 'png'],//接收的文件后缀
            removeFromPreviewOnError:true,
            uploadAsync: false, //false同步,true 异步
            showUpload:false, //是否显示上传按钮
            showRemove :false, //显示移除按钮
            showPreview :true, //是否显示预览
            showCaption:false,//是否显示标题
            showCancel: false, //是否显示文件上传取消按钮
            showClose: false, //是否在预览中显示关闭图标
            browseClass:"", //按钮样式
            zoomIndicator: "",
            dropZoneEnabled: false,//是否显示拖拽区域
            maxFileSize:10240,//单位为kb，如果为0表示不限制文件大小
            maxFileCount:1, //表示允许同时上传的最大文件个数
            autoReplace: true, //达到限制后是否自动替换预览中的文件
            enctype:'multipart/form-data',
            validateInitialCount:true,
            textEncoding:'UTF-8',
            previewFileIcon: "<i class='glyphicon glyphicon-remove'></i>",
            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
            uploadExtraData: function() {   //额外参数的关键点
                var files=$("#"+ownerType).val()
//                console.log("uploadExtraData files: "+files)
                var key=getRandom(28) + files.substr(files.lastIndexOf('.'))
                var description=(files.substr(files.lastIndexOf('\\'))).split('\\')[1]
                var token=getUploadToken()
                var parameter ={
                    "x:opportunityId":opportunityId,
                    "x:type":type,
                    "x:description":description,
                    "key":key,
                    "token":token
                }
//                console.log("parameter:  "+JSON.stringify(parameter))
                return parameter;
            },
        }).on("filebatchselected", function () {
            console.log("***filebatchselected***")
            $("#"+ownerType).fileinput('upload');
        }).on('filebatchuploaderror', function(event, data, msg) {
            console.log("filebatchuploaderror")
        }).on("filebatchuploadsuccess",function(event, data, previewId, index) {
            //批量上传成功后，给第一张图片添加封面
            console.log("filebatchuploadsuccess")
            var result=data.response.files[0]
            console.log("result: "+JSON.stringify(result))
            if(result.status=='200'){
                var url=result.thumbnailUrl
                var type=result.type
                var name=result.name
                $("#fileNames").val(url)
                console.log("fileName.val:  "+$("#fileNames").val())
            }else{
//                $("."+ownerType).val("")
                var url=result.thumbnailUrl
                var type=result.type
                var name=result.name
                $("#fileNames").val(url)
                console.log("fileName.val:  "+$("#fileNames").val())
                console.log(""+result.errorMessage)
            }

        })

    }

    function helpMessage(message) {
            $(".helpMsg").text(message).fadeIn(200);
            setTimeout(function () {
                $(".helpMsg").fadeOut(200);
            }, 1000);
        }
    function getRandom(length)
    {
        var str = Math.random().toString(36).substr(2);
        if (str.length>=length) {
            return str.substr(0, length);
        }
        str += getRandom(length-str.length);
        return str;
    }



</script>
<script>
    $(function () {
        $("#appliedTotalPrice").val("");
        $("#reasonOfPriceAdjustment").val("");

        $("#submitBtn").click(function () {
          var backUrl = $("#backUrl").val()
          // 期望金额
          var appliedTotalPrice = $("#appliedTotalPrice").val().trim();
          if (!appliedTotalPrice) {
              helpMessage("期望押品评估总价未填写");
              return;
          }
          if (appliedTotalPrice <= 0) {
              helpMessage("期望押品评估总价必须大于零");
              return;
          }
          if (!(/^-?[1-9]\d*$/.test(appliedTotalPrice))) {
              helpMessage("期望押品评估总价必须为整数");
              return;
          }

          // 押品特殊因素
          var reasonOfPriceAdjustment = $("#reasonOfPriceAdjustment").val().trim();
          if (!reasonOfPriceAdjustment) {
              helpMessage("押品特殊因素未填写");
              return;
          }

          $.ajax({
              type: "POST",
              url:  "https://" + window.location.host + "/portalForApp/suggestSave",
              data: $('#suggestForm').serialize(),
              beforeSend:function() {
                  $(".helpMsg").text("提交中...")
              },
              success: function (data) {
                  if (data.status == "success") {
                    console.log(backUrl);
                      swal({
                            title: "提交成功，感谢您的反馈",
                            // type: "warning",
                            showCancelButton: true,
                            showConfirmButton: false,
                            confirmButtonColor: "#3aa9dd",
                            confirmButtonText: "精准评估",
                            closeOnConfirm: false,
                            cancelButtonText: "返回",
                            showLoaderOnConfirm:true,
                        },
                        function(isConfirm){
                            if (isConfirm) {
                              var destination = "https://" + window.location.host + "/portalForApp/create3Step1?contact=" + data.contact
                              window.location.href=destination;
                            }else {
                              window.location.href=backUrl;
                                // var a=document.referrer
                                // window.location.href=a
//                                self.location=document.referrer
                              }
                        });


                  } else {
                      helpMessage(data.errorMsg);
                      return;
                  }
              }
          });

          // $("#suggestForm").submit();
        });

        setTimeout(function () {
            $(".message").fadeOut(200);
        }, 2000);

    });
</script>


</body>
</html>
